<?php

/**
 * Menu with project's groups
 * 
 * This class is used to only generate the elements of its menu.
 * Don't use it if you need NESTED elements!
 */

class articlesLeftMenuWidgetComponents extends myComponents
{
    public function executeRender()
    {
        /**
         * Not template-related variables
         */
        $subCategory = $this->getRoute()->getCategoryObject();
        $language    = $this->getRoute()->getParameters();      // Use as $language['p0']

        
        /**
         *  Template variables (persistent)
         */
        $this->groups   = array();    // List of all the categories
        $this->active   = false;      // Whether the current element is active (inside of group)
        $this->projects = '/' . $language['p0'] . '/' . $this->getRoute()->getObject()->getSlug();
  
        
        foreach($this->getProjectGroups() as $singleGroup) {
            $this->groups[] = array(
                'name'  => $singleGroup['Translation'][$this->getUser()->getCulture()]['name'],
                'link'  => '/' . $language['p0'] . '/' . $this->getRoute()->getObject()->getSlug() . '.c/' . $singleGroup['Translation'][$this->getUser()->getCulture()]['slug']
            );
        }

        // Mark an active element
        if($subCategory) {
            $this->active = $subCategory->getSlug();
        }
    }

    /*
     * Get all the products (projects) groups
     */
    private function getProjectGroups()
    {
        return Doctrine::getTable('ProductGroup')->createQuery('pg')
                 ->innerJoin('pg.Translation pgt')
                 ->where('pgt.lang = ?')
                 ->execute(array($this->getUser()->getCulture()), Doctrine_Core::HYDRATE_ARRAY_HIERARCHY);
    }
};